package com.aaa.yq127.dao.impl;



import com.aaa.yq127.dao.DeptDao;
import com.aaa.yq127.util.JDBCUtil;

import java.util.List;
import java.util.Map;

public class DeptDaoImpl implements DeptDao {
    @Override
    public List<Map<String, Object>> all() {
        String sql = "select * from t_dept";
        List<Map<String, Object>> lists = JDBCUtil.queryMap(sql);
        if (lists.size()==0){
            return null;
        }else {
            return lists;
        }
    }

    @Override
    public int deleteDept(int deptid) {
        String sql = "delete from t_dept where deptid=?";
        int delete = JDBCUtil.update(sql, deptid);
        return delete;
    }

    @Override
    public int insertDept(int deptNo, String dname, String remark, int status) {
        String sql = "insert into t_dept values(null,?,?,?,?)";
        int insert = JDBCUtil.update(sql, deptNo, dname, remark, status);
        return insert;
    }

    @Override
    public int updateDept(int deptNo, String dname, String remark, int status, int deptid) {
        String sql = "update t_dept set deptNo=?,dname=?,remark=?,status=? where deptid=?";
        int update = JDBCUtil.update(sql, deptNo, dname, remark, status, deptid);
        return update;
    }
}
